home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CHIP_CD_2004-07.iso / macos / pack1 / files / sd234.sit / Speed Download 2.3.4.dmg / Speed Download 2 / sdcli < prev   
Encoding:
Text File  |  2004-04-01  |  10.3 KB  |  269 lines

  1. #!/bin/sh
  2. #
  3. #Very simple script illustrating how SD can be controlled from the command line
  4. #Don't hesitate to modify it, do tell us if you make some useful mods
  5. #
  6. #
  7. #
  8. #
  9.  
  10. if [ "$1" = 'dl' ];
  11. then
  12.     if [ "$#" -lt 2 ]; then
  13.         echo "Missing url"
  14.     else
  15.         #add the item
  16.         uid=`osascript -e 'tell application "Speed Download 2"'  -e "AddURL \"$2\"" -e 'end tell'` 
  17.         #get it
  18.         res=`osascript -e 'tell application "Speed Download 2"' -e "StartQueuedDownload $uid" -e 'end tell'`
  19.         if [ "$res" -eq -1 ]; then
  20.             echo "Too many downloads active, download queued with uid $uid"
  21.         else
  22.             echo "Download starting, uid for this download is $uid"
  23.         fi
  24.     fi
  25. elif [ "$1" = 'launch' ]; then
  26.         echo `osascript -e 'tell application "Speed Download 2"' -e "activate" -e 'end tell'`
  27. elif [ "$1" = 'startq' ]; then
  28.                 osascript -e 'tell application "Speed Download 2"' -e "StartQueue" -e 'end tell' >/dev/null
  29.         echo "Queue started"
  30. elif [ "$1" = 'stopq' ]; then
  31.                 osascript -e 'tell application "Speed Download 2"' -e "StopQueue" -e 'end tell' >/dev/null
  32.                 echo "Queue stopped"    
  33.  
  34. elif [ "$1" = 'info' ]; then
  35.     if [ "$#" -lt 2 ]; then
  36.                 echo "missing uid"
  37.         else
  38.         echo `osascript -e 'tell application "Speed Download 2"' -e "GetDownloadInfo $2" -e 'end tell'`
  39.     fi
  40. elif [ "$1" = 'add' ]; then
  41.         if [ "$#" -lt 2 ]; then
  42.                 echo "missing url"
  43.         else
  44.                 uid=`osascript -e 'tell application "Speed Download 2"' -e "AddURL \"$2\" startqueue false" -e 'end tell'`
  45.         echo "Item added with uid: $uid"
  46.         fi
  47. elif [ "$1" = 'start' ]; then
  48.         if [ "$#" -lt 2 ]; then
  49.                 echo "missing uid"
  50.         else
  51.                 res=`osascript -e 'tell application "Speed Download 2"' -e "StartQueuedDownload $2" -e 'end tell'`
  52.             if [ $res -eq 0]; then
  53.             echo "Download started"
  54.         elif [ $res -eq -4]; then
  55.             echo "bad uid"
  56.         elif [ $res -eq -1]; then
  57.             echo "too many active downloads"
  58.         fi
  59.     fi
  60. elif [ "$1" = 'stop' ]; then
  61.         if [ "$#" -lt 2 ]; then
  62.                 echo "missing uid"
  63.         else
  64.                 res=`osascript -e 'tell application "Speed Download 2"' -e "CancelDownload $2" -e 'end tell'`
  65.             if [ $res -eq 0 ]; then
  66.             echo "Download removed"
  67.         else echo "Invalid uid"
  68.         fi
  69.     fi
  70. elif [ "$1" = 'remove' ]; then
  71.         if [ "$#" -lt 2 ]; then
  72.                 echo "missing uid"
  73.         else
  74.                 res=`osascript -e 'tell application "Speed Download 2"' -e "Remove $2" -e 'end tell'`
  75.             if [ $res -eq 0 ]; then
  76.             echo "0:element removed";
  77.         elif [ $res -eq -1 ]; then
  78.             echo "-1:element could not be removed because it is in use"
  79.         else
  80.             echo "-2:bad uid"
  81.         fi
  82.     fi
  83. elif [ "$1" = 'clear' ]; then
  84.     res=`osascript -e 'tell application "Speed Download 2"' -e "Clearqueue" -e 'end tell'`
  85.     if [ $res -eq 0 ]; then
  86.         echo "Queue Cleared"
  87.     else
  88.         echo "Queue could not be cleared. elements may be in use"
  89.     fi
  90.  
  91.  elif [ "$1" = 'url' ]; then
  92.         if [ "$#" -lt 2 ]; then
  93.                 echo "missing uid"
  94.         else
  95.                 res=`osascript -e 'tell application "Speed Download 2"' -e "GetDownloadURL $2" -e 'end tell'`
  96.         if [ "$res" = "" ]; then
  97.             echo "Invalid uid"
  98.         else echo $res
  99.         fi
  100.         fi
  101. elif [ "$1" = 'quit' ]; then
  102.     echo `osascript -e 'tell application "Speed Download 2"' -e "quit" -e 'end tell'`
  103. elif [ "$1" = 'list' ]; then
  104.         osascript -e 'tell application "Speed Download 2"' -e "ListQueue" -e 'end tell'
  105. elif [ "$1" = 'listFolder' ]; then    
  106.      if [ "$#" -lt 2 ]; then
  107.                 echo "missing folder id"
  108.         else
  109.         osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents $2" -e 'end tell'
  110.     #    if [ "$res" = "" ]; then
  111.         #                echo "Invalid folder id"
  112.         #        else echo $res
  113.         #        fi
  114.     fi
  115. elif [ "$1" = 'listMain' ]; then
  116.     osascript -e 'tell application "Speed Download 2"' -e "ListFolderContents 1" -e 'end tell'
  117. elif [ "$1" = 'folders' ]; then
  118.         osascript -e 'tell application "Speed Download 2"' -e "ListFolders" -e 'end tell' 
  119. elif [ "$1" = 'rfolders' ]; then
  120.      if [ "$#" -lt 2 ]; then
  121.                 echo "missing host id"
  122.         else
  123.                 osascript -e 'tell application "Speed Download 2"' -e "ListRemoteFolders $2" -e 'end tell'
  124.                 
  125.         fi
  126. elif [ "$1" = 'listRfolder' ]; then
  127.          if [ "$#" -lt 3 ]; then
  128.                 echo "missing host id,uid"
  129.         else
  130.                 osascript -e 'tell application "Speed Download 2"' -e "ListRemoteFolderContents $3 host id $2" -e 'end tell'
  131.                 
  132.                 
  133.         fi                 
  134. elif [ "$1" = 'listR' ]; then
  135.          if [ "$#" -lt 2 ]; then
  136.                 echo "missing host id"
  137.         else
  138.                 osascript -e 'tell application "Speed Download 2"' -e "ListRemoteQueue $2" -e 'end tell'
  139.                 
  140.         fi
  141.  
  142. elif [ "$1" = 'connect' ]; then
  143.          if [ "$#" -lt 2 ]; then
  144.                 echo "missing server address"
  145.         else
  146.                 res=`osascript -e 'tell application "Speed Download 2"' -e "ConnectHost \"$2\" user \"$3\" password \"$4\" " -e 'end tell'`
  147.                 if [ $res -eq 0 ]; then
  148.                         echo "Connection in progress"
  149.                 else echo "Connection attempt failed"
  150.                 fi
  151.         fi
  152.  
  153. elif [ "$1" = 'disconnect' ]; then
  154.          if [ "$#" -lt 2 ]; then
  155.                 echo "missing host id"
  156.         else
  157.                 res=`osascript -e 'tell application "Speed Download 2"' -e "DisconnectHost \"$2\"" -e 'end tell'`
  158.                 if [ $res -eq -1 ]; then 
  159.                         echo "Invalid host ID"
  160.                 else echo "Disconnected"
  161.         fi
  162.     fi
  163. elif [ "$1" = 'refreshHost' ]; then
  164.          if [ "$#" -lt 2 ]; then
  165.                 echo "missing host id"
  166.         else
  167.                 res=`osascript -e 'tell application "Speed Download 2"' -e "RefreshHost $2" -e 'end tell'`
  168.                 if [ $res -eq -1 ]; then
  169.                         echo "Invalid host ID"
  170.                 else echo "refreshing..."
  171.                 fi
  172.                         
  173.         fi
  174. elif [ "$1" = 'listH' ]; then 
  175.     res=`osascript -e 'tell application "Speed Download 2"' -e "ListHosts" -e 'end tell'`
  176.         echo $res
  177. elif [ "$1" = 'connectS' ]; then
  178.     if [ "$#" -lt 2 ]; then
  179.                 echo "missing server name"
  180.     else
  181.                 res=`osascript -e 'tell application "Speed Download 2"' -e "ConnectFavourite \"$2\"" -e 'end tell'`
  182.                 if [ $res -eq -1 ]; then
  183.                         echo "Invalid server name"
  184.                 else echo "connection in progress"
  185.                 fi
  186.         fi
  187. elif [ "$1" = 'listS' ]; then
  188.         osascript -e 'tell application "Speed Download 2"' -e "ListFavourites" -e 'end tell'
  189.         
  190. elif [ "$1" = 'saveS' ]; then
  191.          if [ "$#" -lt 2 ]; then
  192.                 echo "missing host id"
  193.         else
  194.                 res=`osascript -e 'tell application "Speed Download 2"' -e "AddHostToFavourites $2" -e 'end tell'`
  195.         if [ $res -eq -1 ]; then
  196.                         echo "Invalid host ID"
  197.                 else echo "added"
  198.                 fi
  199.         fi
  200. elif [ "$1" = 'removeS' ]; then
  201.         if [ "$#" -lt 2 ]; then
  202.                 echo "missing server name"
  203.         else
  204.                 res=`osascript -e 'tell application "Speed Download 2"' -e "RemoveFavourite \"$2\"" -e 'end tell'`
  205.                 if [ $res -eq -1 ]; then
  206.                         echo "Invalid server name"
  207.                 else echo "removed"
  208.                 fi
  209.         fi
  210.  
  211. elif [ "$1" = 'addRemote' ]; then
  212.     
  213.         if [ "$#" -lt 3 ]; then
  214.                 echo "missing hostID, uid"
  215.         else
  216.            res=`osascript -e 'tell application "Speed Download 2"' -e "AddRemoteItemToQueue $3 host id $2" -e 'end tell'`
  217.                 if [ "$res" = "0" ]; then
  218.                         echo "Invalid hostID/uid"
  219.                 else echo "Item added with uid $res"
  220.                 fi
  221.         fi
  222. elif [ "$1" = 'ddl' ]; then
  223.         
  224.         if [ "$#" -lt 3 ]; then
  225.                 echo "missing hostID, uid"
  226.         else
  227.               res=`osascript -e 'tell application "Speed Download 2"' -e "AddDirectTransfer $2 UID $3" -e 'end tell'`
  228.                 if [ "$res" = "0" ]; then
  229.                         echo "Invalid hostID/uid"
  230.                 else echo "Item added with uid $res"
  231.                 fi
  232.         fi
  233.    
  234. elif [ "$1" = 'bwstats' ]; then
  235.     osascript -e 'tell application "Speed Download 2"' -e "BWstats" -e 'end tell'
  236. else
  237.     echo "usage:"
  238.     echo "sdcli launch            opens Speed Download 2"
  239.     echo "sdcli dl <url>            downloads the specified url, returns a uid"
  240.     echo "sdcli add <url>            Adds the specified url to the queue, without downloading it, returns a uid"
  241.     echo "sdcli stop <uid>        cancels the download corresponding to the uid"
  242.     echo "sdcli start <uid>        starts the download corresponding to the uid"
  243.     echo "sdcli remove <uid>        removes the download corresponding to the uid"
  244.     echo "sdcli clear            removes all downloads"
  245.     echo "sdcli info <uid>        returns a status string for the specified uid"
  246.     echo "sdcli url <uid>            returns the url for the specified uid"
  247.     echo "sdcli list            lists all uids and and urls on the local machine"
  248.     echo "sdcli startq            starts the queue"
  249.     echo "sdcli stopq             stops the queue"
  250.     echo "sdcli quit            quit Speed Download 2"
  251.     echo "sdcli listFolder <uid>        lists the contents of the local folder with the specified uid"
  252.     echo "sdcli listMain            lists the contents of my downloads"
  253.     echo "sdcli folders            lists the local folders"
  254.     echo "sdcli listRFolder <hostID> <uid> lists the contents of the folder with uid <uid> on the host specified"
  255.     echo "sdcli listR <hostID>        lists all the urls on the specified remote host"
  256.     echo "sdcli rfolders <hostID>        lists the folders on the specified host"
  257.     echo "sdcli connect <address>        initiates a connection to the specified address"
  258.     echo "sdcli disconnect <hostID>    disconnects the specified connection"
  259.     echo "sdcli listH            lists active connections"
  260.     echo "sdcli connectS <name>        connects the named server from my servers"
  261.     echo "sdcli listS            lists the servers in my servers, and their status"    
  262.     echo "sdcli saveS <hostID>         saves the specified connection in my servers"
  263.     echo "sdcli removeS <name>         removes the named entry from my servers"
  264.     echo "sdcli addRemote <hostID> <uid>     adds the specified download from a remote host to the local host"
  265.     echo "sdcli refreshHost <hostID>     refreshes the specified host"
  266.     echo "sdcli bwstats        Displays bandwidth usage"
  267.     echo "sdcli ddl <hostID> <uid>        adds the specified download from a remote host to the local host as a direct transfer"
  268. fi
  269.